package com.ruoyi.home.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.home.domain.*;
import com.ruoyi.home.service.ITSfContractService;
import com.ruoyi.home.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.home.mapper.TSfContractMapper;
import com.ruoyi.home.domain.TSfContract;

/**
 * 【业主管理】Service业务层处理
 * 
 * @author weishu
 * @date 2021-07-21
 */
@Service
public class TSfContractServiceImpl implements ITSfContractService
{
    @Autowired
    private TSfContractMapper tSfContractMapper;

    /**
     * 查询收房列表
     * @param tSfContract 收房
     * @return 收房
     */
    @Override
    public List<TSfContract> selectTSfContractList(TSfContract tSfContract)
    {
        List<TSfContract> tSfContracts = tSfContractMapper.selectTSfContractList(tSfContract);
        for (TSfContract list:  tSfContracts  ) {
            list.setReserve3(DateUtil.getDateString(list.getConInfoTime(),"yyyy-MM-dd"));
            list.setReserve4(DateUtil.getDateString(list.getConAudTime(),"yyyy-MM-dd"));
        }
        return tSfContracts;
    }

    /**
     * 业主查询列表
     * @param tSfContract 收房
     * @return 收房
     */
    @Override
    public List<TSfContract> selectTSfContractOwner(TSfContract tSfContract) {
        List<TSfContract> tSfContracts = tSfContractMapper.selectTSfContractOwner(tSfContract);
        return tSfContracts;
    }
    /**
     * 选择房源列表查询
     * @return 收房
     */
    @Override
    public List<TSHouseInfoDto> selectTSfContractXzfc(TSHouseInfoDto tsHouseInfoDto) {
        List<TSHouseInfoDto> tsHouseInfoDtos = tSfContractMapper.selectTSfContractXzfc(tsHouseInfoDto);
        return tsHouseInfoDtos;
    }

    /**
     * 选择银行列表查询
     * @return 银行
     */
    @Override
    public List<TBankDto> selectTSfContractBank(TBankDto tBankDto) {
        List<TBankDto> tBankDtos = tSfContractMapper.selectTSfContractBank(tBankDto);
        return tBankDtos;
    }
    /**
     * 选择地区列表查询
     * @return 省
     */
    @Override
    public List<TRegionDto> selectTSfContractRegion(int i) {
        List<TRegionDto> tRegionDtos = tSfContractMapper.selectTSfContractRegion(i);
        return tRegionDtos;
    }

    /*添加图片*/
    @Override
    public void addpic(Map<String, Object> pic) {
        tSfContractMapper.addpic(pic);
    }

    /*添加业主表*/
    @Override
    public void addpic(Map<String, Object> pic) {

    }

    @Override
    public int addOwnerService(TSfContract tSfContract) {
        return 0;
    }

    @Override
    public int insertTSfContract(TSfContract tSfContract) {
        return 0;
    }

    /**
     * 收房合同查询   续约
     * @param
     * @return
     * 郭豪
     */
    @Override
    public int addOwnerService(TSfContract tSfContract) {
        TMOwner tmOwner = new TMOwner();
        tmOwner.setOwnerName(tSfContract.getOwnerName());//名称
        tmOwner.setCertificateType("身份证");//证件类型
        tmOwner.setIdCard(tSfContract.getOwnerIdCard());//身份证g
        tmOwner.setMobile(tSfContract.getOwnerMobile());//手机号
        tmOwner.setAddress(tSfContract.getOwnerContactAddress());//联系人地址
        tmOwner.setUrgMobile(tSfContract.getSignUserEmergencyPhone());//紧急联系人电话
        tmOwner.setBankCard(tSfContract.getBankCard());//银行卡号
        tmOwner.setBankUserName(tSfContract.getBankUserName());//持卡人姓名
        tmOwner.setBankUserIdCard(tSfContract.getBankUserIdCard());//持卡人身份证
        tmOwner.setBankName(tSfContract.getBankName());//银行名称
        tmOwner.setAccountName(tSfContract.getAccountName());//账户名称
        tmOwner.setBankBranchCodeLh(tSfContract.getBankBranchCodeLh());//联行行号
        tmOwner.setBankAccountProvince(tSfContract.getBankAccountProvince());//开户行所在省ID
        tmOwner.setContractId(17L);
        return  tSfContractMapper.addOwner(tmOwner);
    }

    /*添加合同表*/
    @Override
    public int insertTSfContract(TSfContract tSfContract) {

        TSfContract tSfContract1 = new TSfContract();
        /*给新创建的实例赋值*/
        BeanUtils.copy(tSfContract,tSfContract1);
        /*合同编号*/
        String s = UUID.randomUUID().toString();
        tSfContract1.setSfContractNo(s);
        /*房产编号*/
        String s1 = UUID.randomUUID().toString();
        tSfContract1.setHouseId(s1);
        /*获取对应的用户更新用id*/
        Long userId = SecurityUtils.getUserId();
        tSfContract1.setUpdateUserid(userId);
        /*收房合同录入人*/
        tSfContract1.setOperId(userId);
        /*收房合同人*/
        tSfContract1.setSfUserId(userId);
        /*合同录入时间*/
        tSfContract1.setConInfoTime(new Date());
        /*合同审核时间*/
        tSfContract1.setConAudTime(new Date());
        /*合同签订时间*/
        tSfContract1.setConSignTime(new Date());
        return tSfContractMapper.insertTSfContract(tSfContract1);
    }









}
